import {logout} from "@/api/AuthApi.js";
import {ElLoading, ElMessage} from "element-plus";
import {deleteCookie} from "@/util/CookieUtil.js";
import router from "@/router/index.js";

// 登出
export function logOut() {
    const loading = ElLoading.service({
        lock: true,
        text: '登出...',
        background: 'rgba(0, 0, 0, 0.7)',
    });
    logout().then(resp=>{
        ElMessage({
            message: '登出成功！',
            type: 'success',
        });
        deleteCookie('token');
        loading.close();
        router.push("/home");
        location.reload();
    }).catch(err=>{
        ElMessage({
            message: '登出失败！',
            type: 'warning',
        });
        loading.close();
    });
}